feat(android): jetpack compose support#1092
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the Android implementation of RNCViewPager from a ViewPager2-backed view hierarchy to a Jetpack Compose-backed pager (HorizontalPager / VerticalPager) while keeping the existing React Native manager API surface.
Changes:
- Replaces the Android native view implementation with a new
ComposePagerViewthat hosts RN child views viaAndroidView. - Rewires the RN
ViewGroupManagerand manager-impl helpers to operate onComposePagerViewinstead ofNestedScrollableHost/ViewPager2. - Adds Compose Gradle configuration and Compose dependencies to the Android module.
Reviewed changes
Copilot reviewed 5 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt | Redirects child management and prop setters to ComposePagerView methods. |
| android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt | Switches the manager’s view type to ComposePagerView and forwards commands/props accordingly. |
| android/src/main/java/com/reactnativepagerview/ComposePagerView.kt | New Compose-based pager implementation, including event dispatching and RN-child hosting. |
| android/gradle.properties | Introduces a Compose version property for dependency management. |
| android/build.gradle | Enables Compose + adds Kotlin Compose plugin and Compose dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "name": "react-native-pager-view", | ||
| "version": "8.0.2", | ||
| "version": "9.0.0-rc.0", |
There was a problem hiding this comment.
revert this before the release
# Conflicts: # example/bun.lockb # package.json
49b47ff to
fd6e484
Compare
| composeView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) | ||
| composeView.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow) | ||
| applyOverScrollMode() |
| LaunchedEffect(pageCount) { | ||
| if (!didEmitInitialPage) { | ||
| didEmitInitialPage = true | ||
| currentPage = pagerState.currentPage | ||
| dispatchPageSelected(pagerState.currentPage) | ||
| } | ||
|
|
||
| if (pagerState.currentPage >= pageCount) { | ||
| val target = pageCount - 1 | ||
| pagerState.scrollToPage(target) | ||
| currentPage = target | ||
| dispatchPageSelected(target) | ||
| } | ||
| } |
| private fun getBeyondViewportPageCount(): Int { | ||
| return if (offscreenPageLimitState.value == DEFAULT_OFFSCREEN_PAGE_LIMIT) { | ||
| DEFAULT_BEYOND_VIEWPORT_PAGE_COUNT | ||
| } else { | ||
| offscreenPageLimitState.value.coerceAtLeast(0) | ||
| } | ||
| } |
| { | ||
| "name": "react-native-pager-view", | ||
| "version": "8.0.4", | ||
| "version": "9.0.0-rc.1", |
There was a problem hiding this comment.
revert this version
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 11 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
android/src/main/java/com/reactnativepagerview/ComposePagerView.kt:605
offscreenPageLimitis documented as needing to be > 0 (or default). Clamping to 0 here silently accepts an invalid value and changes behavior versus the previous ViewPager2-backed implementation (which rejects values < 1 except-1). Consider clamping to at least 1 for non-default values.
private fun getBeyondViewportPageCount(): Int {
return if (offscreenPageLimitState.value == DEFAULT_OFFSCREEN_PAGE_LIMIT) {
DEFAULT_BEYOND_VIEWPORT_PAGE_COUNT
} else {
offscreenPageLimitState.value.coerceAtLeast(0)
}
| composeView.measure( | ||
| MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), | ||
| MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) | ||
| ) |
Summary
This PR replaces the Android pager implementation with a Jetpack Compose-backed pager while preserving the existing
React Native manager API.
Changes
ComposePagerView, backed by ComposeHorizontalPagerandVerticalPager.